Object.defineProperty(exports, "__esModule", {
  value: true
});
var $z1SoundManager = require("SoundManager");
var $z1Tool = require("Tool");
var $z1Pool = require("Pool");
var $z1Bullet2 = require("Bullet2");
var $z1DieEff2 = require("DieEff2");
var $z1Gate2 = require("Gate2");
var $z1Num2 = require("Num2");
var $z1Role2 = require("Role2");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_BattleGround2Ctrl = function (e) {
  function _ctor() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.jsonAssets = [];
    t.pools = [];
    t.startNode = null;
    t.endNode = null;
    t.hpProgBar = null;
    t.hitAni = null;
    t.atkStr = null;
    t.WIDTH = 600;
    t.state = 10;
    t.baseLineY = -500;
    t.endLineY = -500;
    t.player = null;
    t.winTCount = -99999999;
    t.hp = [3, 3];
    t.waveEnemyHandles = [[], [], [], [], [], []];
    t.bulletHandles = [];
    return t;
  }
  var o;
  __extends(_ctor, e);
  o = _ctor;
  _ctor.prototype.start = function () {
    var e = ["ConfigBattle"];
    var t = function (t) {
      o.JSONManager[e[t]] = {};
      n.jsonAssets[t].json.map(function (a) {
        o.JSONManager[e[t]][a.id] = a;
      });
    };
    var n = this;
    for (var i = 0; i < this.jsonAssets.length; i++) {
      t(i);
    }
    this.baseLineY = this.startNode.y;
    this.endLineY = this.endNode.y;
    this.state = 10;
    this.createNewPlayer();
    setTimeout(function () {
      $z1SoundManager.default.playBgm(0);
    }, 1e3);
    cc.director.getCollisionManager().enabled = true;
  };
  _ctor.prototype.createNewPlayer = function () {
    var e = this.pools[4].getComponent($z1Pool.default).getNewPoolItem();
    this.player = e;
    e.setPosition(new cc.Vec2(0, this.baseLineY));
    e.getComponent($z1Role2.default).init({
      team: 0,
      rId: 1,
      par: this
    });
  };
  _ctor.prototype.createNewEnemy = function (e, t, o) {
    undefined === o && (o = {});
    var a = this.pools[0].getComponent($z1Pool.default).getNewPoolItem();
    a.setPosition(new cc.Vec2(e, t));
    a.getComponent($z1Role2.default).init({
      team: 1,
      rId: o.rId,
      config: o.config,
      par: this
    });
    return a;
  };
  _ctor.prototype.createNewBullet = function (e, t, o) {
    var a = this.pools[2].getComponent($z1Pool.default).getNewPoolItem();
    o.par = this;
    a.getComponent($z1Bullet2.default).init(e, t, o);
  };
  _ctor.prototype.createNewHpNum = function (e) {
    var t = this.pools[1].getComponent($z1Pool.default).getNewPoolItem();
    t.getComponent($z1Num2.default).initAsHp(e);
    return t;
  };
  _ctor.prototype.createNewHitNum = function () {};
  _ctor.prototype.createNewDieEff = function (e) {
    var t = this.pools[5].getComponent($z1Pool.default).getNewPoolItem();
    t.setPosition(e.position);
    t.getComponent($z1DieEff2.default).init();
  };
  _ctor.prototype.createNewGate = function (e) {
    undefined === e && (e = {});
    var t = this.pools[3].getComponent($z1Pool.default).getNewPoolItem();
    t.y = 800;
    var o = [];
    for (var a = 1; a <= 5; a++) {
      0 !== e["door" + a] && o.push(a);
    }
    var c = $z1Tool.default.randomFromArr2(o, 2);
    $z1Tool.default.shuffle(c);
    var s = [[c[0], e["door" + c[0]]], [c[1], e["door" + c[1]]]];
    t.getComponent($z1Gate2.default).init({
      par: this,
      gateInfo: s
    });
  };
  _ctor.prototype.beHit = function () {
    this.hitAni.play();
    this.hp[0]--;
    this.hpProgBar.progress = this.hp[0] / this.hp[1];
    if (this.hp[0] <= 0) {
      console.log("game over.");
      cc.popupManager.popup("game2", "win", "UIGame2End", {
        ad: false,
        scale: true
      }, false);
      this.state = 0;
    }
  };
  _ctor.prototype.refreshAtk = function () {
    this.atkStr.string = "" + this.player.getComponent($z1Role2.default).bulletConfig.dmg;
  };
  _ctor.prototype.showPauseMenu = function () {
    this.state = 0;
    cc.popupManager.popup("game2", "set", "UIGame2Set", {
      scale: false
    }, this);
  };
  _ctor.prototype.hidePauseMenu = function () {
    this.state = 10;
  };
  _ctor.prototype.update = function (e) {
    if (10 === this.state && this.winTCount > 0) {
      this.winTCount -= e;
      this.winTCount <= 0 && cc.popupManager.popup("game2", "win", "UIGame2End", {
        ad: false,
        scale: true
      }, true);
    }
  };
  _ctor.JSONManager = {
    ConfigBattle: {}
  };
  __decorate([ccp_property(cc.JsonAsset)], _ctor.prototype, "jsonAssets", undefined);
  __decorate([ccp_property(cc.Node)], _ctor.prototype, "pools", undefined);
  __decorate([ccp_property(cc.Node)], _ctor.prototype, "startNode", undefined);
  __decorate([ccp_property(cc.Node)], _ctor.prototype, "endNode", undefined);
  __decorate([ccp_property(cc.ProgressBar)], _ctor.prototype, "hpProgBar", undefined);
  __decorate([ccp_property(cc.Animation)], _ctor.prototype, "hitAni", undefined);
  __decorate([ccp_property(cc.Label)], _ctor.prototype, "atkStr", undefined);
  return o = __decorate([ccp_ccclass], _ctor);
}(cc.Component);
exports.default = def_BattleGround2Ctrl;